package com.ayou.eggguard.user.mapper;

import com.ayou.eggguard.user.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {

    @Insert("insert into user(username,password,create_time,update_time) " +
            "values(#{username},#{password},now(),now())")
    void addUser(String username, String password);

    @Select("select * from user where username=#{username}")
    User getUserById(String username);

    @Select("select * from user where username=#{username}")
    User getUserByUserName(String username);

    @Update("update user set user_realName=#{userRealName},user_age=#{userAge},user_gender=#{userGender}," +
            "email=#{email},user_pic=#{userPic},update_time=#{updateTime} where username=#{username}")
    void updateUserInfo(User user);

    @Update("update user set password=#{md5String} where username=#{username}")
    void updatePwd(String username, String md5String);

    List<User> getUserListByPage(String username);

    @Update("update user set open=case " +
            "when open=0 then 1 " +
            "when open=1 then 0 end " +
            "where id=#{id}")
    void userOpen(Integer id);
}
